/**面向对象全通
 *1 类、继承、构造、重载、继承、阻止继承，多态
 * 2025/8/6
 */

class Person {
    public String name;
    private int age;
    //默认构造
    public Person() {
        this("无名",0);
    }
    public Person(String name, int age) {
        this.name= name;
        this.age= age;
    }
    public void callOut(){
        System.out.println(name+":"+age);
    }
    //重载
    public void setAge(int age){
        this.age= age;
    }
    public void setAge(){
        this.age= 0;
    }
}

//*****Java只能单继承
class Student extends Person{
    public String classroom ;
    Student(String classroom){
        super();//必须放在第一个，super为父类，可以这样构造
        //特别的
        //如果父类没有默认的构造方法，子类就必须显式调用super()并给出参数以便让编译器定位到父类的一个合适的构造方法。
        //这里还顺带引出了另一个问题：即子类不会继承任何父类的构造方法。子类默认的构造方法是编译器自动生成的，不是继承的。
        this.classroom= classroom;
    }

    public void studentInfo(){
        System.out.println(super.name+":"+this.classroom);
    }
}
//send
class Income {
    protected double income;
    public double getTax() {
        return income * 0.1; // 税率10%
    }
}
class Salary extends Income {
    @Override
    public double getTax() {
        if (income <= 5000) {
            return 0;
        }
        return (income - 5000) * 0.2;
    }
}
class StateCouncilSpecialAllowance extends Income {
    @Override
    public double getTax() {
        return 0;
    }
}

public class Main {

    public static void main(String[] args) {
    Person a = new Person();
    Person b = new Person("牢大",34);
    a.callOut();
    b.callOut();
    Shape rect = new Rect(3,4);
    Shape tri = new Tri(5,4);
    System.out.println("rect:"+rect.area()+" tri:"+tri.area());


    }

}